import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.joda.time.LocalTime;

//@author A0099943J
public class Task implements Comparable<Task>{
	private String taskDescription;
	private DateTime taskStartDateTime,taskEndDateTime;
	private boolean completed;
	
	//@author A0099943J
	public Task(Task task) {
		taskDescription = task.getDescription();
		taskStartDateTime = task.getStartDateTime();
		taskEndDateTime = task.getEndDateTime();
		completed = task.getStatus();
	}
	
	//@author A0099943J
	public Task(String description,DateTime startDT,DateTime endDT, boolean status) {
		taskDescription = description;
		taskStartDateTime = startDT;
		taskEndDateTime = endDT;
		completed = status;
	}
	
	//@author A0099943J
	public Task(String description,DateTime startDT, DateTime endDT) {
		this(description,startDT,endDT,false);
	}
	
	//@author A0099943J
	public Task(String _desc,DateTime endDT, boolean status) {
		this(_desc,endDT,endDT, status);
	}
	
	//@author A0099943J
	public Task(String _desc,DateTime endDT) {
		this(_desc,endDT,false);
	}
	
	//@author A0099943J
	public Task(String _desc) {
		this(_desc,DateTime.now().withTime(23,59,0,0));
	}
	
	//@author A0099943J
	public boolean isTimedTask() {
		if(!taskStartDateTime.equals(taskEndDateTime)) {
			return true;
		} 
		else {
			return false;
		}
	}
	
	//@author A0099943J
	public String getDescription() {
		return taskDescription;
	}
	
	//@author A0099943J
	public LocalTime getDueTime() {
		return taskEndDateTime.toLocalTime();
	}
	
	//@author A0099943J
	public LocalDate getDueDate() {
		return taskEndDateTime.toLocalDate();
	}
	
	//@author A0099943J
	public LocalTime getStartTime() {
		return taskStartDateTime.toLocalTime();
	}
	
	//@author A0099943J
	public LocalDate getStartDate() {
		return taskStartDateTime.toLocalDate();
	}
	
	//@author A0099943J
	public String getYear() {
		int year = getDueDate().year().get();
		return getFormat(year);
	}
	
	//@author A0099943J
	public String getMonth() {
		int month = getDueDate().monthOfYear().get();
		return getFormat(month);
	}

	//@author A0099943J
	public String getDay() {
		int day = getDueDate().dayOfMonth().get();
		return getFormat(day);
	}

	//@author A0099943J
	public String getHour() {
		int hour = getDueTime().hourOfDay().get();
		return getFormat(hour);
	}

	//@author A0099943J
	public String getMinute() {
		int minute = getDueTime().minuteOfHour().get();
		return getFormat(minute);
	}
	
	//@author A0099943J
	public String sDayOfWeek() {
		int day = getStartDate().dayOfWeek().get();
		return getDayFormat(day);
	}
	
	//@author A0099943J
	public String eDayOfWeek() {
		int day = getDueDate().dayOfWeek().get();
		return getDayFormat(day);
	}

	//@author A0099943J
	public String getDayFormat(int day) {
		switch (day) {
		case 1:	return "Mon";

		case 2:	return "Tue";

		case 3: return "Wed";

		case 4: return "Thu";

		case 5: return "Fri";

		case 6: return "Sat";

		case 7:	return "Sun";

		default:return "invalid";
		
		}
	}
	
	//@author A0099943J
	public String getSYear() {
		int year = getStartDate().year().get();
		return getFormat(year);
	}
	
	//@author A0099943J
	public String getSMonth() {
		int month = getStartDate().monthOfYear().get();
		return getFormat(month);
	}

	//@author A0099943J
	public String getSDay() {
		int day = getStartDate().dayOfMonth().get();
		return getFormat(day);
	}

	//@author A0099943J
	public String getSHour() {
		int hour = getStartTime().hourOfDay().get();
		return getFormat(hour);
	}

	//@author A0099943J
	public String getSMinute() {
		int minute = getStartTime().minuteOfHour().get();
		return getFormat(minute);
	}
	
	//@author A0099943J
	public String getFormat(int DTProperty) {
		String formatted = (DTProperty < 10 ? "0" : "").concat(Integer.toString(DTProperty));
		return formatted;
	}
	
	//@author A0099943J
	public DateTime getEndDateTime() {
		return taskEndDateTime;
	}
	
	//@author A0099943J
	public DateTime getStartDateTime() {
		return taskStartDateTime;
	}
	
	//@author A0099943J
	public boolean getStatus() {
		return completed;
	}
	
	//@author A0099943J
	public void setDescription(String newDesc) {
		taskDescription = newDesc;
	}
	
	//@author A0099943J
	public void setStartDateTime(DateTime newSDT) {
		taskStartDateTime = newSDT;
	}
	
	//@author A0099943J
	public void setEndDateTime(DateTime newEDT) {
		taskEndDateTime = newEDT;
	}
	
	//@author A0099943J
	public void setStartDate(int year, int monthOfYear, int dayOfMonth) {
		taskStartDateTime = taskStartDateTime.withDate(year,monthOfYear,dayOfMonth);
	}
	
	//@author A0099943J
	public void setEndDate(int year,int monthOfYear,int dayOfMonth) {
		taskEndDateTime = taskEndDateTime.withDate(year,monthOfYear,dayOfMonth);
	}
	
	//@author A0099943J
	public void setStartTime(int hour,int minute) {
		taskStartDateTime = taskStartDateTime.withTime(hour,minute,0,0);
	}
	
	//@author A0099943J
	public void setEndTime(int hour,int minute) {
		taskEndDateTime = taskEndDateTime.withTime(hour,minute,0,0);
	}
	
	//@author A0099943J
	public void setStatus(boolean status) {
		completed = status;
	}
	
	//@author A0099943J
	public boolean contains(DateTime dt) {
		boolean contain = taskStartDateTime.isEqual(dt)   ||
						  taskEndDateTime.isEqual(dt)     ||
						 (taskStartDateTime.isBefore(dt)  && 
						  taskEndDateTime.isAfter(dt)     );
		
		return contain;
	}
	
	//@author A0099943J
	public boolean containsDate(LocalDate date) {
		LocalDate startDate = getStartDate(),
				  endDate	= getDueDate();
		boolean contain 	=  startDate.isEqual(date)	||
							   endDate.isEqual(date)	||
							  (startDate.isBefore(date) &&
							   endDate.isAfter(date)    );
		return contain;
	}
	
	//@author A0099943J
	public boolean isEqual(Task other) {
		return (this.compareTo(other) == 0);
	}
	
	/* (non-Javadoc)
	 * @see java.lang.Comparable#compareTo(java.lang.Object)
	 */
	//@author A0099943J
	@Override
	public int compareTo(Task other) {
		int 		  ret = taskEndDateTime.compareTo(other.getEndDateTime());
		if (ret == 0) ret = taskStartDateTime.compareTo(other.getStartDateTime());
		if (ret == 0) ret = taskDescription.compareTo(other.getDescription());
		return ret;
	}
}
